import { reqGetHotelList, reqGetCityList, reqGetHotelAll } from '@/api'
// 小仓库
const state = {
  hotelList: [],
  cityList: [],
  cityActiveNum: 0,
  hotelALL: [],
  showBigImg: {}
}
const mutations = {
  GETHOTELLIST(state, { result, num }) {
    state.hotelList = result.data
    state.cityActiveNum = num
  },
  GETCITYLIST(state, cityList) {
    let map = new Map();
    for (let item of cityList) {
      if (!map.has(item.province_id)) {
        map.set(item.province_id, item);
      };
    };
    let arr = [...map.values()];
    state.cityList = arr
  },
  GETHOTELALL(state, hotelALL) {
    state.hotelALL = hotelALL
  },
  SHOWBIGIMG(state, { imgUrl, tag }) {
    state.showBigImg = {
      imgUrl,
      tag
    }
  }
}
const actions = {
  async getHotelList({ commit }, { id, num }) {
    let result = await reqGetHotelList(id)
    // console.log(result);
    if (result.status == 200) {
      commit("GETHOTELLIST", { result, num })
    }
  },
  async getCityList({ commit }) {
    let result = await reqGetCityList()
    // console.log(result);
    if (result.status == 200) {
      commit("GETCITYLIST", result.data)
    }
  },
  async getHotelAll({ commit }) {
    let result = await reqGetHotelAll()
    // console.log(result);
    if (result.status == 200) {
      commit("GETHOTELALL", result.data)
    }
  },
  showBigImg({ commit }, { imgUrl, tag }) {
    commit("SHOWBIGIMG", { imgUrl, tag })
  }
}
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters
}